﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;
using ZeCloud.Techdays.Model;

namespace ZeCloud.Techdays.Business
{
    public class ServiceContext : TableServiceContext
    {
        public ServiceContext(CloudStorageAccount account)
            : base(account.TableEndpoint.ToString(), account.Credentials)
        {

            var tableClient = account.CreateCloudTableClient();
            tableClient.CreateTableIfNotExist("Question");
        }

        public IQueryable<Question> Questions
        {
            get { return this.CreateQuery<Question>("Question"); }
        }

        public void Insert(Question question)
        {
            question.PartitionKey = "Techdays2012";
            question.RowKey = Guid.NewGuid().ToString();
            

            this.AddObject("Question", question);
            this.SaveChanges();
        }
    }
}